package com.example.sys.org.mapping;

import com.example.core.constant.Constant;
import com.example.core.mapping.BaseMapping;
import com.example.core.utils.StringUtils;
import com.example.sys.org.po.SysDept;
import com.example.sys.org.po.SysElement;
import com.example.sys.org.service.SysElementService;
import com.example.sys.org.vo.SysDeptVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SysDeptMapping extends BaseMapping<SysDept, SysDeptVo> {

    @Resource
    private SysElementService sysElementService;

    @Override
    public void toPo(SysDeptVo vo, SysDept po) throws Exception {
        String hierarchyId = new String();
        if (StringUtils.isNotEmpty(vo.getParentId())) {
            SysElement sysElement = sysElementService.getById(vo.getParentId());
            hierarchyId = sysElement.getHierarchy();
            po.setParentName(sysElement.getName());
            hierarchyId = hierarchyId + po.getId() + Constant.X;
        } else {
            hierarchyId = Constant.X + po.getId() + Constant.X;
        }
        po.setHierarchy(hierarchyId);
    }

    @Override
    public void toVo(SysDept po, SysDeptVo vo) throws Exception {

    }
}
